package com.lzx.es.controller;

import com.lzx.common.utils.R;
import com.lzx.es.entity.answerVO.RequestParams;
import com.lzx.es.entity.userVO.QueryUser;
import com.lzx.es.service.ESProblemService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/es/web")
public class ESProblemController {
    @Resource
    private ESProblemService esProblemService;

    //用户修改头像或昵称，批量更新数据
    @PutMapping("/problem/updateUserNicknameOrAvatar")
    public R updateUserNicknameOrAvatar(@RequestBody QueryUser queryUser) {
        return esProblemService.updateUserNicknameOrAvatar(queryUser);
    }

    //修改问题
    @PutMapping("/editProblem/{problemId}")
    public R editProblem(@PathVariable Long problemId) {
        return esProblemService.editProblem(problemId);
    }

    //自动补全
    @GetMapping("/problem/suggestion/{key}")
    public R getSuggestion(@PathVariable String key) {
        return esProblemService.getSuggestion(key);
    }

    //将数据重新导入es
    @PostMapping("/saveProblemList")
    public R saveProblemList() {
        return esProblemService.saveProblemList();
    }

    //全文检索
    @PostMapping("/searchProblem")
    public R searchProblem(@RequestBody RequestParams requestParams) {
        return esProblemService.searchProblem(requestParams);
    }
}
